function ListNode(val) {
    this.val = val;
    this.next = null;
}

// 从第n位开始 逆序
function reverseList(head, m, n) {
    let dummy = new ListNode(0);
    dummy.next = head;

    let temHead = dummy;
    // 找到起始位置
    for (let i = 0; i < m - 1; i++) {
        temHead = temHead.next
    }

    var pre = null;
    var curr = temHead.next;
    for (let j = 0; j <= n - m; j++) {
        var next = curr.next
        temHead.next = pre;
        pre = curr;
        curr = next;
    }

    temHead.next.next = curr
    temHead.next = pre
    return dummy.next
}